﻿
@{
    ViewData["Title"] = "ReservoirAreaIndex";
    Layout = null;
}

<link href="~/libs/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />

    @* 查询条件 *@
    <form class="layui-form layui-row layui-col-space16">
        <div class="layui-col-sm3">
        <input type="text" name="areaName" placeholder="库区名称" class="layui-input">
        </div>

        <button type="button" class="layui-btn layui-bg-blue" id="searchButton">查询</button>
        <button type="button" class="layui-btn">重置</button>

        <button type="button" class="layui-btn layui-btn-primary" lay-on="test-page-custom" onclick="addReturn()">
            新增
        </button>

    </form>

    @* 显示数据表格 *@
        <table class="layui-hide" id="areaData" lay-filter="areaData" style="margin-top: 20px;margin-left: 20px">
        </table>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="backto">库区</a>
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="upd">修改</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
    </script>

<script src="~/libs/layui-v2.5.6/layui/layui.js"></script>
<script src="~/libs/jquery/jquery.js"></script>
    <script>
        layui.use(['table', 'form'], function () {
            var table = layui.table;
            var form = layui.form;
            
            function show() {
                table.render({
                    elem: '#areaData',
                    url: '/ReservoirArea/GetReservoirAreaList', // 实际接口地址
               
                    page: true, // 开启分页
                    limit: 10, // 每页默认显示的条数
                    limits: [10, 20, 30], // 每页条数的选择项
                    cols: [
                        [
                            { field: 'areaCode', title: '库区编码', width: 120 },
                            { field: 'areaName', title: '库区名称', width: 120 },
                            { field: 'areaCapacity', title: '面积', width: 120 },
                          
                            {
                                field: 'isArea',
                                title: '是否冻结',
                                templet: function (d) {
                                return '<input type="checkbox" ' + (d.isArea ? 'checked' : '') + ' name="isArea" lay-skin="switch" lay-filter="switchTest" title="是否">';
                            },
                                width: 110,
                                key: 'isArea'
                            },
                            { field: 'resultArea', title: '备注', width: 120 },
                            { title: '操作', fixed: 'right', width: 200, align: 'center', toolbar: '#barDemo' }
                        ]
                    ],
                    where: {
                        areaName: $('#areaName').val(),
                        setCode:@ViewBag.setCode
                    },
                    parseData: function (res) {
                        return {
                            code: res.code,
                            count: res.data.rowCount,
                            data: res.data.queryable
                        };
                    },
                });
            }
            show();

            // 查询
            $("#searchButton").on("click", function () {
                show();
            });

            table.on('tool(areaData)', function (obj) {
                var data = obj.data; // 获取当前行数据
                if (obj.event === 'delete') {

                    layer.confirm('确定要删除吗？', {
                        btn: ['确定', '取消'] // 按钮
                    }, function () {
                        $.ajax({
                        url: '/ReservoirArea/ReservoirAreaDelete',
                            type: 'post',
                            data: {
                                id: data.id
                            },
                            success: function (res) {
                                if (res.msg == '删除成功') {
                                    layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                                        location.reload(); // 刷新页面
                                    });
                                } else {
                                    layer.msg(res.msg, { icon: 2, time: 1000 });
                                }
                            }
                        });
                    }, function () {
                        layer.msg('已取消', { icon: 1, time: 1000 });
                    });
                }
                if (obj.event === 'upd') {                
                    // iframe层
                    layer.open({
                        type: 2,
                        title: '修改客户数据',
                        shadeClose: true,
                        shade: 0.5,
                        area: ['600px', '60%'],
                        content: '/ReservoirArea/ReservoirAreaUpdateIndex?id=' + data.id, // iframe的src
                        end: function () {
                            // iframe层关闭后刷新页面
                            location.reload(); // 刷新页面
                        }
                    });
                }
                 if (obj.event === 'backto') {
                    // iframe层
                    layer.open({
                        type: 2,
                        title: '库位设置',
                        shadeClose: true,
                        shade: 0.5,
                        area: ['100%', '100%'],
                        content: '/BinSet/BinSetIndex?areaCode=' + data.areaCode, // iframe的src
                        end: function () {
                            // iframe层关闭后刷新页面
                            location.reload(); // 刷新页面
                        }
                    });
                }
       
            });
        });

             function addReturn() {
                console.log("添加仓库设置");
                // iframe层
                layer.open({
                    type: 2,
                    title: '添加仓库设置',
                    shadeClose: true,
                    shade: 0.5,
                    area: ['600px', '60%'],
                    content: '/ReservoirArea/ReservoirAreaAddIndex', // iframe的src
                    end: function () {
                        // iframe层关闭后刷新页面
                        location.reload(); // 刷新页面
                    }
                });
            }
</script>
